package com.example.ylgh.controller;

import com.example.result.Result;
import com.example.ylgh.model.hosp.HospitalSet;
import com.example.ylgh.service.HospitalSetService;
import com.example.ylgh.vo.hosp.HospitalSetQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hx
 * @create 2022/5/7 10:55
 * description:
 */
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
//@CrossOrigin
public class HospitalSetController {

    @Autowired
    private HospitalSetService hospitalSetService;

    @GetMapping("findAll")
    public Result findAllHospitalSet(){
        List<HospitalSet> hospitalSetList = hospitalSetService.list();
        return Result.ok(hospitalSetList);
    }

    /**
     * 条件分页查询
     * @param current
     * @param limit
     * @param hospitalSetQueryVo
     * @return
     */
    @PostMapping("/findPageHospSet/{current}/{limit}")
    public Result findPageHospSet(@PathVariable long current,
                                  @PathVariable long limit,
                                  @RequestBody HospitalSetQueryVo hospitalSetQueryVo){
       return hospitalSetService.findPageHospSet(current,limit,hospitalSetQueryVo);
    }

    /**
     * 新增医院数据
     * @param hospitalSet
     * @return
     */
    @PostMapping("/saveHospSet")
    public Result saveHospSet(@RequestBody HospitalSet hospitalSet){
        return hospitalSetService.saveHospSet(hospitalSet);
    }

    @DeleteMapping("/{id}")
    public Result deleteHosp(@PathVariable long id){
        boolean b = hospitalSetService.removeById(id);
        if (b){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    /**
     * 根据id寻找医院数据
     * @param id
     * @return
     */
    @GetMapping("/getHospSet/{id}")
    public Result getHospSet(@PathVariable long id){
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        return Result.ok(hospitalSet);
    }

    /**
     * 修改医院信息
     * @param hospitalSet
     * @return
     */
    @PutMapping("/updateHospSet")
    public Result updateHospSet(@RequestBody HospitalSet hospitalSet){
        boolean update = hospitalSetService.updateById(hospitalSet);
        if (update){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    /**
     * 批量删除
     * @param idList
     * @return
     */
    @DeleteMapping("/batchRemove")
    public Result batchRemoveHospSet(@RequestBody List<Long> idList){
        boolean b = hospitalSetService.removeByIds(idList);
        if (b){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    /**
     * 设置医院锁和状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/lockHospSet/{id}/{status}")
    public Result lockHospSet(@PathVariable long id, @PathVariable Integer status){
        return hospitalSetService.lockHospSet(id,status);
    }

    //发送短信密钥
    @PutMapping("/sendKey/{id}")
    public Result sendKey(@PathVariable long id){
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        String hoscode = hospitalSet.getHoscode();
        String signKey = hospitalSet.getSignKey();
        // TODO: 2022/5/7 发送短信
        return Result.ok();

    }

}
